package com.itheima.controller.mapping;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author robin
 * @version 1.0
 * 学习目标： @RequestMapping使用
 * 1.开发经常使用地方
 * 2.常用的注解属性
 */
@Controller
@RequestMapping("/user")
public class UserController {

    /**
     * @TODO 需求1：当请求http://localhost:8080/hello时，springmvc启动是否有问题？该如何处理？
     * @RequestMapping("/users")+@RequestMapping("/hello")===>/users/hello
     */
    @RequestMapping("/hello")
    public String hello(Model model) {
        model.addAttribute("name", "user!");
        return "success";
    }

    /**
     * @TODO 需求2：当请求GET http://localhost:8080/user/hello2 时，springmvc如何限制请求方式只能是get请求如何办到？
     */
    //@RequestMapping(value = "hello2", method = RequestMethod.GET)
    @PostMapping("/hello2")
    public String hello2(Model model) {
        model.addAttribute("name", "user2!");
        return "success";
    }
}
